package com.coreservlets.jsf.ss06;

/**
* This is a comment.
*/
import javax.faces.bean.ManagedBean;

@ManagedBean
public class BankingBean 
{
	private String customerId, password;

	public String getCustomerId() 
	{
		return customerId;
	}

	public void setCustomerId(String customerId) 
	{
		this.customerId = customerId.trim();
		
		if( this.customerId.isEmpty())
		{
			this.customerId = "(none entered)";
		}
	}

	public String getPassword()
	{
		return(password);
	}

	public void setPassword(String password) 
	{
		this.password = password;
	}
	
	
	private static ICustomerLookupService lookupService = new CustomerSimpleMap();
	
	
	public String showBalance()
	{
		if( !getPassword().equals( "secret" ) )
		{
			return( "wrong-password");
		}
		
		customer = lookupService.findCustomer( customerId );
		
		if( customer == null )
		{
			return( "unknown-customer");
		}
		else if( customer.getBalance() < 0 )
		{
			return( "negative-balance");
		}
		else if( customer.getBalance() < 10000 )
		{
			return( "normal-balance");
		} 
		else
		{
			return( "high-balance");
		}
	}
	
	private Customer customer;
	
	public Customer getCustomer()
	{
		return( customer );
	}
	
	public void setCustomer( Customer customer )
	{
		this.customer = customer;
	}
}